<template>
<div class="content">
    <mt-header fixed title="维保单位">
        <div slot="left">
            <mt-button icon="back" @click.native="goback()">返回</mt-button>
        </div>
    </mt-header>
 <mt-loadmore  :bottom-method="loadBottom" :autoFill="autoFill" :bottom-all-loaded="allLoaded" ref="loadmore">
    <mt-cell v-for="(item) in mymaitainorList" :key="item.maintainor" :title="item.commanyname" @click.native="goToDetails(item.maintainor)">
    </mt-cell>
</mt-loadmore>
    <div>
      <not-data-page v-show="mymaitainorList.length === 0"></not-data-page>
    </div>
    </div>
</template>
<script>
import notDataPage from '@/component/notQueryDataPage.vue'
export default {
  data () {
    return {
      mymaitainorList: [],
      autoFill: false,
      allLoaded: false,
      pages: 0,
      page: 1,
      pagesize: 20
    }
  },
  components: {
    notDataPage
  },
  created () {
    this.mymaitainors(0)
  },
  methods: {
    goback () {
      this.$router.go(-1)
    },
    async mymaitainors (type) {
      const res = await this.$store.dispatch('mymaitainors', {
        page: this.page,
        pagesize: this.pagesize})
      if (res.status === '0') {
        this.pages = res.context ? res.context.length : 0
        type ? this.mymaitainorList = [...this.mymaitainorList, ...res.context] : this.mymaitainorList = [...res.context]
      }
    },
    goToDetails (maintainor) {
      this.$router.push({
        path: '/maitainordetails',
        query: {maintainor}
      })
    },
    async loadBottom () {
      this.$refs.loadmore.onBottomLoaded()
      if (this.pages < this.pagesize) {
        this.allLoaded = true
        return
      }
      this.page++
      await this.mymaitainors(1)
    }
  }
}
</script>
<style lang="less" scoped>
.content{
  padding-top: 40px;
}
</style>
